<template>
<div style="display:flex;">
	<el-tree :data="data2" :props="defaultProps" style="width:300px;margin-top:21px;border:0"
	 @node-click="getName" v-loading="treeLoading">
	</el-tree>
	<el-form ref="form" :model="form" label-width="80px" @submit.prevent="onSubmit" style="margin:20px;width:60%;min-width:600px;">
		<el-form-item label="名字">
			<el-input v-model="form.typeresourcesname"></el-input>
		</el-form-item>
		<el-form-item label="英文名">
			<el-input v-model="form.name"></el-input>
		</el-form-item>
		<el-form-item label="路径">
			<el-input v-model="form.url"></el-input>
		</el-form-item>
		<el-form-item label="图标">
			<el-input v-model="form.name4"></el-input>
		</el-form-item>
		<el-form-item label="备注">
			<el-input type="textarea" v-model="form.desc"></el-input>
		</el-form-item>
	</el-form>
</div>	
</template>

<script>
import Vue from 'vue'
import Element from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import $ from 'jquery'
import util from 'src/js/util'
Vue.use(Element)

	export default {
		data() {
			return {
				treeLoading:false,
				form: {
					typeresourcesname: '',
					url:'',
				},
				data2:[],
				defaultProps: {
          				children: 'children',
          				label: 'typeresourcesname'
        				},
        				
							}
		},
		methods: {
			onSubmit() {
				console.log('submit!');

			},
			getName:function(res){
				this.form = res;
			},
			getResources() {
			this.treeLoading = true;
			var tokenname = sessionStorage.getItem("key");
			var rolename = sessionStorage.getItem("rolename");
			var _this = this;
			$.ajax({
				type:"GET",
				url:"http://101.200.56.75/apis/resources/getrolenameResourcesList?rolename="+rolename+"&token="+tokenname+"&sort=resourcesid,asc",
				dataType:"JSON",
				success:function(msg){
					if(msg.payload!="token 过期或者token不存在 请重新登陆"){
						if(msg.payload.content!="该角色名没有资源"){
							if(msg.payload.fail==0){
								_this.treeLoading = false;
								_this.$alert(msg.payload,{
									type:'warning'
								})
								}else{
								_this.treeLoading = false;
								_this.data2 = msg.payload.content;
								}
						}else{
						_this.treeLoading = false;
						_this.$alert(msg.payload.content,{
							type:'warning'
						})
						}
					}else{
					_this.$alert(msg.payload,{
						type:'warning'
					});
					_this.$router.push({ path: '/login' });
					}
				}
			});	
			}
			
		},
		mounted() {
			this.getResources();
		}
		
	}

</script>
<style scoped>

</style>